package com.ad.pet.wxapi;

import android.app.Activity;

import com.ad.pet.api.ApiService;
import com.ad.pet.app.RxDisposable;
import com.ad.pet.common.data.http.AppSubscriber;
import com.ad.pet.common.structure.mvp.AbsBasePresenter;
import com.ad.pet.models.remote.PayResult;

import javax.inject.Inject;

/**
 * Created by SEELE on 2018/4/11.
 */
public class PayPresenter extends AbsBasePresenter implements PayContract.Presenter {

    private ApiService mApiService;
    private PayContract.View mView;

    private Activity mActivity;

    private RxDisposable mRxDisposable;

    @Inject
    public PayPresenter(ApiService apiService,
                                  Activity activity, RxDisposable rxDisposable) {
        mApiService = apiService;
        mActivity = activity;
        mRxDisposable = rxDisposable;
    }

    @Override
    public void onCreate(PayContract.View view) {
        this.mView = view;
    }


    @Override
    public void onDestroy() {
        if (mRxDisposable != null)
        mRxDisposable.clear();
        if (mActivity != null) mActivity = null;
        mView = null;
    }







    @Override
    public void upPayresult(String payType,String payment_typeBODY) {
        mRxDisposable.add(mApiService.write_notify_log(payType,payment_typeBODY)
                .subscribe(new AppSubscriber<PayResult>(mView) {
                    @Override
                    public void next(PayResult user) {
                        mView.upPayresultSuccess(user);
                    }
                }));
    }
}
